//
//  HJRetweetView.swift
//  Weibo
//
//  Created by 韩佳 on 16/4/21.
//  Copyright © 2016年 ddg. All rights reserved.
//

import UIKit
import SnapKit

class HJRetweetView: UIView {
    var bottomCons:Constraint?
    var statueViewModel:HJStatusViewModel? {
        didSet{
//           contentLabel.text = statueViewModel?.status?.retweeted_status?.text
            contentLabel.text = statueViewModel?.retweentText
            
            bottomCons?.uninstall()
            if let pic_urls = statueViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count > 0{
                
                //元组属性赋值
                pictureView.dataInfo = (pic_urls,statueViewModel!.retweetPictureViewSize)
                
                //pictureView赋值
                pictureView.pic_urls = pic_urls
                //显示
                pictureView.hidden = false
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    bottomCons = make.bottom.equalTo(pictureView).offset(HJStatusCellMargin).constraint
                })
            }else{
                pictureView.hidden = true
                self.snp_makeConstraints(closure: { (make) -> Void in
                    bottomCons = make.bottom.equalTo(contentLabel).offset(HJStatusCellMargin).constraint
                })
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        backgroundColor = UIColor(white: 242/255, alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.leading.equalTo(self).offset(HJStatusCellMargin)

        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(HJStatusCellMargin)
            make.leading.equalTo(contentLabel)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        self.snp_makeConstraints { (make) -> Void in
            bottomCons =  make.bottom.equalTo(pictureView).offset(HJStatusCellMargin).constraint
            
        }
        
    }
    //转发正文
    private lazy var contentLabel:UILabel = {
        let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: HJStatusCellContentFont, preferredMaxLayoutWidth: ScreenWidth - 2 * HJStatusCellMargin)
        return label
    }()
    //配图
    private lazy var pictureView:HJStatusPictureView = HJStatusPictureView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
}
